package hn.cch.indicator;

import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;

import java.util.List;
import java.util.stream.Collectors;

public class Sharpe implements Indicator {
    @Override
    public Double indicator(List<Return> R) {
        Double meanPortfolio = R.stream().collect(Collectors.averagingDouble(Return::getRp));
        Double meanRiskFree = R.stream().collect(Collectors.averagingDouble(Return::getRf));

        double[] Rp = R.stream().map(Return::getRp).mapToDouble(Double::doubleValue).toArray();
        double sigma = new StandardDeviation(false).evaluate(Rp);

        Double sharpe = (meanPortfolio - meanRiskFree) / sigma;
        return sharpe;
    }
}
